package vue.affectation;

import java.util.Arrays;
import java.util.Vector;

import javax.swing.JPanel;
import javax.swing.border.TitledBorder;

import metier.Stage;
import vue.commun.JPanJTable;
import vue.commun.JPanOptionTri;
import configuration.Constante;
import ctr.commun.CommunGest;

public class JPanAffAffectation extends JPanel{

	private static final long serialVersionUID = -8258905260255616984L;
	private JPanJTable panJTable;
	private JPanOptionTri jPanOptionTri;
	
	public JPanAffAffectation(JPanOptionTri jPanOptionTri, JPanJTable panJTable) {
		this.jPanOptionTri = jPanOptionTri;
		if ( panJTable != null ){
			this.panJTable = panJTable; 
		}
		init();
	}
	
	public JPanAffAffectation() {
		init();
	}
	
	private void init(){
		CommunGest communGest = new CommunGest();
		if ( jPanOptionTri == null){
			jPanOptionTri = new JPanOptionTri(true, this);
		}
		this.add(jPanOptionTri);
		
		// ----------- AFFICHAGE TABLEAU
		JPanel tableau = new JPanel();
		if (panJTable == null ){
			//nom des colonnes
			Vector<Object> nomColonne= new Vector<Object>(Arrays.asList(new String[] {"nom","date de debut", "date de fin"}));
			
			//valeurs des lignes
			Vector<Vector<Object>> dataVector= new Vector<Vector<Object>>();
			
			// Ajout d'un vector stage.
			for (Stage stage : communGest.getListeStage()) {
				dataVector.add(stage.getVector());
			}
			panJTable = new JPanJTable(null, dataVector, nomColonne, null);
			// Methode TRES TRES simple pour trier, mais vu le lendemain........
			panJTable.getJtable().setAutoCreateRowSorter(true);
		}
		tableau.add(panJTable);
		this.add(tableau);
	}

	/**
	 * @return the panJTable
	 */
	public JPanJTable getPanJTable() {
		return panJTable;
	}
}
